Ext.namespace("Doc");

Doc.ToImportant = function() {
	this.winView = null;
	
	this.txtDocNum = new Ext.form.TextField({
		name : 'docNum',
		width: 150
	});
	this.txtDocTitle = new Ext.form.TextField({
		name : 'docTitle',
		width: 150
	});
	this.dtStart = new Ext.form.DateField({
		width: 85,
		name : 'docDateFm',
		format: 'Y-m-d'
	});
	this.dtEnd = new Ext.form.DateField({
		width: 85,
		name : 'docDateFm',
		format: 'Y-m-d'
	});
	this.btnTrans = new Ext.Toolbar.Button({
        iconCls: 'icon-newplan',
        text: '转重要问题',
        tooltip: {text: '转重要问题'},
        handler: this.onTrans,
        scope: this
    });
    this.btnSearch = new Ext.Toolbar.Button({
        iconCls: 'icon-search',
        text: '查找',
        tooltip: {text: '查找公文'},
        handler: this.queryDoc,
        scope: this
    });
		
	this.store = new Ext.data.JsonStore({
	    url: '../superviseDoc/toImportantDoc.form?timesnap=' + Date.parse(new Date()),
	    root: 'result',
	    totalProperty: 'total',
        remoteSort: true,
	    fields: ['superviseId','superviseType','importantFlag','superviseState','closeFlag','createId',
		    'managerId','createTime','docId','docNum','docTitle','docDispatchDeptId','notion','auditor',
		    'docDate','principal','inspector','inspectDate','docContent','docType','receiveDeptId',
		    'editorId','editDate','origin','dispatchDeptName','receiveDeptName','inspectorName',
		    'principalName','principalDept','feedback','fulfill']
	});
	this.store.setDefaultSort('DocId', 'desc');
	this.renderType = function(value){
		return OMS.DOC_TYPE[value];
	};
	this.sm =  new Ext.grid.CheckboxSelectionModel();
	this.column = [
		this.sm,
		{header: '公文ID', sortable: true, align: 'right',hidden:true,width: 20,dataIndex: 'docId'},
		{header: '公文编号', sortable: true, align: 'center',width: 20,dataIndex: 'docNum'},
		{header: '公文名称', sortable: true, align: 'center',width: 20,dataIndex: 'docTitle'},
		{header: '发文部门ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'docDispatchDeptId'},
		{header: '发文部门', sortable: true, align: 'center',width: 20,dataIndex: 'dispatchDeptName'},
		{header: '领导人批示意见', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'notion'},
		{header: '批示人', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'auditor'},
		{header: '批示日期', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'docDate'},
		{header: '阅处人', sortable: true, align: 'center',hidden:true,width: 20,dataIndex: 'inspectorName'},
		{header: '阅处负责人ID', sortable: true, align: 'center',hidden:true,width: 20,dataIndex: 'principal'},
		{header: '阅处负责人', sortable: true, align: 'center',width: 20,dataIndex: 'principalName'},
		{header: '阅处部门', sortable: true, align: 'center',hidden:true,width: 20,dataIndex: 'principalDept'},
		{header: '阅处人ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'inspector'},
		{header: '阅处日期', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'inspectDate'},
		{header: '发文内容', sortable: true, align: 'center',width: 20,dataIndex: 'docContent'},
		{header: '公文类别', sortable: true, align: 'right',width: 20,dataIndex: 'docType',renderer:this.renderType},
		{header: '收文部门ID', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'receiveDeptId'},
		{header: '收文部门', sortable: true, align: 'center',width: 20,dataIndex: 'receiveDeptName'},
		{header: '填报人', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'editorId'},
		{header: '填报日期', sortable: true, align: 'right',width: 20,dataIndex: 'editDate'},
		{header: '来源', sortable: true,hidden:true, align: 'right',width: 20,dataIndex: 'origin'},
		{header: '督办ID', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'superviseId'},
		{header: '督办类型', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'superviseType'},
		{header: '已转重要问题', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'importFlag'},
		{header: '状态', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'superviseState'},
		{header: '归档标志', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'closeFlag'},
		{header: '创建人', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'createId'},
		{header: '督办负责人', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'managerId'},
		{header: '创建时间', sortable: true, align: 'right',width: 20,hidden:true,dataIndex: 'createTime'},
		{header: '反馈情况', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'feedback'},
		{header: '落实情况', sortable: true, align: 'center',width: 20,hidden:true,dataIndex: 'fulfill'}
	];
			
	Doc.ToImportant.superclass.constructor.call(this, {
		title: '待转重要问题督办',
        region: 'center',
        cm: new Ext.grid.ColumnModel(this.column),
        sm: this.sm,
        tbar: [this.btnTrans,'->','公文编号:', this.txtDocNum,'公文名称:', this.txtDocTitle, 
		          '填报时间:', this.dtStart, '~', this.dtEnd,this.btnSearch],
        bbar:new Ext.PagingToolbar({
			 pageSize: 15,
	         store: this.store,
	         displayInfo: true,
	         displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
	         emptyMsg: "没有记录..."
		}),
        store:this.store,
        viewConfig: { forceFit: true },
        listeners:{
        	rowdblclick : this.onViewDoc,
			//render:this.queryDoc
			activate: this.queryDoc
		}
    });
};
Ext.extend(Doc.ToImportant, Ext.grid.GridPanel, {
	queryDoc:function(btn,event){
		var param={
			start : 0,
			limit : 15,
			docDateFm:this.dtStart.getValue(),
			docDateTo:this.dtEnd.getValue(),
			docNum:this.txtDocNum.getValue(),
			docTitle:this.txtDocTitle.getValue()
		};
		this.store.load({
			params:param
		});
	},
	onTrans: function(btn, event) {		
		var records = this.getSelectionModel().getSelections();
		if(records.length==0){
			Utils.warn2('请选择一条督办！',180);
			return ;
		}
		var ids='';
		for(var i=0;i<records.length;i++){
			ids+=records[i].data['superviseId']+',';
		}
		scope=this;
		Ext.Ajax.request({
		   url: '../superviseDoc/transImportant.form?timesnap=' + Date.parse(new Date()),
		   params: {ids:ids},
		   success: function(){
			Utils.info2();
		   	scope.queryDoc();
		   }
		});	
	},
	onViewDoc:function(grid, rowIndex,e){		
		if (this.winView == null) {
			this.winView = new Doc.View(this);
		}
		this.winView.show();
		this.winView.initWin(grid.store.getAt(rowIndex).data);		
	}
});
